import { GameData } from "../Data/GameData";
import GameManager from "../Manager/GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class WinPanel extends cc.Component {
    public static Instance: WinPanel;

    @property(cc.Node)
    public Button_back: cc.Node = null;
    @property(cc.Node)
    public Button_nextStage: cc.Node = null;

    onLoad() {
        WinPanel.Instance = this;
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    Refresh() {
    }

    AddListener() {
        this.Button_back.on(cc.Node.EventType.TOUCH_START, this.On_Button_back, this);
        this.Button_nextStage.on(cc.Node.EventType.TOUCH_START, this.On_Button_nextStage, this);
    }

    RemoveListener() {
        this.Button_back.off(cc.Node.EventType.TOUCH_START, this.On_Button_back, this);
        this.Button_nextStage.off(cc.Node.EventType.TOUCH_START, this.On_Button_nextStage, this);
    }

    // On_Button_ok() {
    //     GameManager.Instance.StartGame();
    // }

    On_Button_back() {
        this.ShowOff();
        GameManager.Instance.ExitGame();
    }

    On_Button_nextStage() {
        this.ShowOff();

        GameData.CurrentLevel++;
        cc.director.loadScene("GameScene");
    }
}